﻿using UnityEngine;
using System.Collections;
using DG.Tweening;
using System;
using System.Collections.Generic;


namespace DevelopTools.UI
{
    /// <summary>
    /// UI移动缩放控制
    /// </summary>
    [Serializable]
    public class UIMotion : MonoBehaviour
    {

        public float MotionTime = 3f;
        public List<Transform> listPosition;
        public List<Vector3Rotate> listRotate;
        public List<Vector3Scale> listScale;



        public List<GameObject> listGameObjectUI;
        //[SerializeField]
        private static float moveT;
        private static float rotateT;
        private static float scaleT;
        public static void SetMotionTime(float MoveTimes, float RotateTimes, float ScaleTimes)
        {
            moveT = MoveTimes;
            rotateT = RotateTimes;
            scaleT = ScaleTimes;
        }
        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            for (int i = 0; i < listGameObjectUI.Count; i++)
            {
                listGameObjectUI[i].GetComponent<RectTransform>().localScale = Vector3.zero;
                listGameObjectUI[i].GetComponent<RectTransform>().rotation = Quaternion.identity;
            }
            //设置缩放
            listScale = new List<Vector3Scale>();
            //手动添加缩放的比例
            listScale.Add(new Vector3Scale(1, 1, 1));

            //设置旋转
            //listRotate = new List<Vector3Rotate>();
            //listRotate.Add(new Vector3Rotate(0, 0, 360));


        }

        void Awake()
        {
            Init();
        }

        // Use this for initialization
        void Start()
        {
            //DOTween.Init(false, true, LogBehaviour.ErrorsOnly);
            Scale(MotionTime);
            
        }

        // Update is called once per frame
        void Update()
        {

        }

        /// <summary>
        /// 移动UI
        /// </summary>
        /// <param name="movingTime">移动时间</param>
        public void Move(float movingTime)
        {
            for (int i = 0; i < listPosition.Count; i++)
            {
                for (int j = 0; j < listGameObjectUI.Count; j++)
                {
                    listGameObjectUI[j].transform.DOMove(listPosition[i].position, movingTime);
                }
            }
        }
        /// <summary>
        /// 旋转UI
        /// </summary>
        /// <param name="rotateTime">旋转时间</param>
        public void Rotate(float rotateTime)
        {
            for (int i = 0; i < listRotate.Count; i++)
            {
                for (int j = 0; j < listGameObjectUI.Count; j++)
                {
                    listGameObjectUI[j].transform.DORotate(new Vector3(listRotate[i].xRotate, listRotate[i].yRotate, listRotate[i].zRotate), rotateTime,
                        RotateMode.FastBeyond360);
                }
            }
        }
        /// <summary>
        /// 缩放UI
        /// </summary>
        /// <param name="scaleTime">缩放时间</param>
        public void Scale(float scaleTime)
        {
            for (int i = 0; i < listScale.Count; i++)
            {
                for (int j = 0; j < listGameObjectUI.Count; j++)
                {
                    listGameObjectUI[j].transform.DOScaleX(listScale[i].xScale, scaleTime);
                    listGameObjectUI[j].transform.DOScaleY(listScale[i].yScale, scaleTime);
                    listGameObjectUI[j].transform.DOScaleZ(listScale[i].zScale, scaleTime);
                }
            }
        }
        public struct Vector3Rotate
        {
            public Vector3Rotate(float x, float y, float z)
            {
                xRotate = x;
                yRotate = y;
                zRotate = z;
            }

            public float xRotate;
            public float yRotate;
            public float zRotate;
        }

        public struct Vector3Scale
        {
            public Vector3Scale(float x, float y, float z)
            {
                xScale = x;
                yScale = y;
                zScale = z;
            }

            public float xScale;
            public float yScale;
            public float zScale;
        }
    }
}